package cn.file;

import java.io.*;

public class FileUtils {


    /**
     * 读取文件行文本
     * 方法简介:
     * 业务背景:
     *
     * @param filePath 文件路径
     * @return {@link String }
     **/
    public static String readFileLineText(String filePath) {
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder stringBuilder = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line).append("/n");
            }
            return stringBuilder.toString();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    public static void writer(String filePath, String content) throws IOException {
        try (PrintWriter writer = new PrintWriter(new FileWriter(filePath, true))) {
            writer.println(content); // Adds a new line at the end
        }
    }

    public static void main(String[] args) {
        String s = readFileLineText("C:\\Users\\Administrator\\Desktop\\address.txt");
        String[] split = s.split("/n");
        for (String string : split) {
            System.out.println(string);
        }

    }

}